package cn.hbads.support.compare.supoort;

import org.javers.core.diff.custom.CustomValueComparator;

import java.math.BigDecimal;
import java.util.Objects;

public class BigDecimalComparator implements CustomValueComparator<BigDecimal> {
    @Override
    public boolean equals(BigDecimal a, BigDecimal b) {
        if (Objects.isNull(a) && Objects.isNull(b)) {
            return true;
        } else if (Objects.nonNull(a) && Objects.nonNull(b)) {
            return a.compareTo(b) == 0;
        } else {
            return false;
        }
    }

    @Override
    public String toString(BigDecimal value) {
        return value.stripTrailingZeros().toPlainString();
    }
}